﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpubFactory.Common
{
    public static class StringExtenstion
    {
        public static IEnumerable<T> Explode<T>(this string v)
        {
            if (v == null)
            {
                return null;
            }
            if (string.IsNullOrWhiteSpace(v))
            {
                return Enumerable.Empty<T>();
            }
            return v.Split(new string[] { ",", "，", " ", "\n", "\t" },
                     StringSplitOptions.RemoveEmptyEntries).Where(s => !string.IsNullOrWhiteSpace(s)).Select(d => (T)Convert.ChangeType(d.Trim(), typeof(T)));
        }
    }
    public class StringUtil
    {
        public static string FormatWordCount(int wordCount)
        {
            if (wordCount > 10000)
            {
                return (wordCount / 10000) + " 万";
            }
            return wordCount.ToString();
        }
        public static string ExtractHost(string url)
        {
            var uri = (new Uri(url));
            return string.Format("{0}://{1}", uri.Scheme, uri.Host);
        }
    }
}
